package org.timeismoney.payment.service.impl;

import java.util.List;

import org.timeismoney.payment.common.PageBean;
import org.timeismoney.payment.model.ItemUnitDetail;
import org.timeismoney.payment.service.ItemUnitDetailService;
import org.timeismoney.payment.service.PaymentRecordService;

public class ItemUnitDetailServiceImpl extends
		BaseServiceImpl<ItemUnitDetail, Integer> implements
		ItemUnitDetailService {
	private PaymentRecordService paymentRecordService;

	public void setPaymentRecordService(PaymentRecordService paymentRecordService) {
		this.paymentRecordService = paymentRecordService;
	}

	public List<ItemUnitDetail> findDetailByYearAndUnit(Integer schoolYearNo,
			Integer unitNo, PageBean<ItemUnitDetail> pageBean) {

		String query = "from ItemUnitDetail ud left join fetch ud.item where ud.schoolYear.schoolYearNo=? and ud.unit.unitNo=?";
		return getDao().find(query, pageBean, schoolYearNo, unitNo).getItems();
	}

	public List<ItemUnitDetail> findDetailByYearAndUnit(Integer schoolYearNo,
			Integer unitNo) {

		String query = "from ItemUnitDetail ud left join fetch ud.item where ud.schoolYear.schoolYearNo=? and ud.unit.unitNo=?";
		return getDao().find(query, schoolYearNo, unitNo);
	}

	@Override
	public void delete(ItemUnitDetail e) {
		paymentRecordService.deleteByItemPaymentNo(e.getItemPaymentNo());
		super.delete(e);
	}

}
